<!DOCTYPE html>
<html>
<?php $this->load->view('admin/public/header.html');?>

<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form" style="display: flex">
            <div class="layui-inline">
                <div class="layui-input-inline" style="display:flex; ">
                    <input type="text" class="layui-input searchVal2" placeholder="请输入订单编号"  style="display: block; width: 140px;margin-right: 10px;" />
                    <input type="text" class="layui-input searchVal3" placeholder="请输入用户姓名"  style="display: block; width: 140px;margin-right: 10px;" />
                    <div class="layui-form-item magt">
                        <label class="layui-form-label">有无图片</label>
                        <div class="layui-input-block" style="width: 140px">
                            <select name="has_image" class="searchVal4" lay-verify="require" lay-search >
                                <option value="">请选择</option>
                                <option value="0">无图</option>
                                <option value="1">有图</option>
                            </select>
                        </div>
                    </div>
                    <a class="layui-btn search_btn" data-type="reload" style="display: block;margin-left: 30px; ">搜索</a>
                </div>
            </div>
        </form>
    </blockquote>



    <table id="newsList" lay-filter="newsList" style="width: 100%; height: 100%"></table>


    <!--操作-->
    <script type="text/html" id="newsListBar">
        <a class="layui-btn layui-btn-xs"  lay-event="check">查看详情</a>
        <a class="layui-btn layui-btn-xs"  lay-event="repaly">回复</a>
        <a class="layui-btn layui-btn-xs"  lay-event="del">屏蔽</a>
    </script>
</form>
<script type="text/javascript">

    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table,
            page;
        //列表
        var tableIns = table.render({
            elem: '#newsList',
            url : '<?php echo site_url("seller/comment/getCompany")?>',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limit : 20,
            limits : [10,15,20,25],

            id : "newsListTable",
            cols : [[
                {field: 'commentId', title: 'ID', width:80, align:"center",sort:true},
                {field: 'realName', title: '发帖人',  width:120},
                {field: 'trade_no', title: '订单编号', width:150},
                {field: 'content', title: '评论内容', width:220},
                {field: 'zanNum', title: '点赞数量', width:90, align:"center"},
                {field: 'replyNum', title: '回复数量', width:90, align:"center"},
                {field: 'createTime', title: '评价时间', width:200},


                {title: '操作', field:'tools', templet:'#newsListBar',fixed:"right",align:"center"}
            ]],
            response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                ,statusCode: 200 //成功的状态码，默认：0
                ,msgName: 'msg' //状态信息的字段名称，默认：msg
                ,countName: 'count' //数据总数的字段名称，默认：count
                ,dataName: 'data' //数据列表的字段名称，默认：data
            } ,
            done:function(res,curr,count){
                page=curr;
            }
        });

        //搜索
        $(".search_btn").on("click",function(){
            table.reload("newsListTable",{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    payTitle: $(".searchVal1").val(),  //订单标题
                    trade_no: $(".searchVal2").val(),  //订单编号
                    realName: $(".searchVal3").val(),  //用户姓名
                    has_image: $(".searchVal4").val(),  //用户姓名
                }
            })
        });

        function addNews(edit){
            var index = layui.layer.open({
                title : "用户信息",
                type : 2,
                content : "<?php echo site_url('seller/comment/repaly')?>",		//iframe层时,这个参数传URL
                success : function(layero, index){
                    var body = layui.layer.getChildFrame('body', index);
                    if(edit){
                        body.find("[name=tocommentId]").val(edit.commentId);
                        body.find("[name=type]").val('company');
                        form.render();
                    }

                    setTimeout(function(){
                        layui.layer.tips('点击返回', '.layui-layer-setwin .layui-layer-close', {
                            tips: 3
                        });
                    },500)
                }
            })
            layui.layer.full(index);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize",function(){
                layui.layer.full(index);
            })
        }

        $(".addNews_btn").click(function(){
            addNews();
        })
        table.on('tool(newsList)', function(obj){
            console.log(obj)
            var layEvent = obj.event,
                data = obj.data;		//用户数据
            if(layEvent === 'check'){ //编辑
                location.href="<?php echo site_url('seller/comment/add?commentId=')?>"+data.commentId;
            } else if(layEvent === 'repaly') {
                // location.href="<?php echo site_url('seller/comment/repaly?commentId=')?>"+data.commentId;
                addNews(data);
            }else if(layEvent === 'del'){ //删除
                layer.confirm('确定删除此项目？',{icon:3, title:'提示信息'},function(index){
                    console.log(data.commentId);
                    $.ajax({
                        type:'post',
                        data:{commentId:data.commentId},
                        dataType: "json",
                        url:"<?php echo site_url('seller/comment/del')?>",
                        success:function(res){
                            if(res.code==200){
                                obj.del();
                                layer.close(index);
                                layer.msg('删除成功');
                            }else{
                                layer.msg('删除失败');
                            }
                        },
                        fail:function(){
                            layer.msg('删除失败');
                        }
                    })

                });
            }
        });

    })

</script>
</body>
</html>